﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using MenesDroid;


namespace XNA_Game_Engine
{   

    class StateButton
    {
        private bool isActived;        
        private Texture2D actived, deactived;
        private Rectangle boundingBox;

        public System.EventHandler OnClickEvent;

        public StateButton(Rectangle position, Texture2D activedTex, Texture2D deactivedTex, System.EventHandler clickedEvent)
        {
            boundingBox = position;
            actived = activedTex;
            deactived = deactivedTex;
            isActived = false;
            OnClickEvent = clickedEvent;
        }

        public void Update()
        {
            if (Input.MouseLeftButtonJustPressed)
            {
                if( Input.MouseInBox( boundingBox ) )
                    this.Trigger();
            }
        }

        public void Render(SpriteBatch renderTarget)
        {
            if( isActived )
                renderTarget.Draw(actived, boundingBox, Color.White);
            else
                renderTarget.Draw(deactived, boundingBox, Color.White);
        }

        public void Trigger()
        {
            isActived = isActived ? false : true;
            OnClickEvent(null, null);
        }

        public bool IsActived
        {
            get { return isActived; }
            set { isActived = value; }
        }

    }
}
